module BorrowingsHelper
  def format_state(state)
    case state
      when Borrowing::STATE_BORROWED then 'Borrowed'
      when Borrowing::STATE_RETURNED then 'Returned'
      else state
    end
  end
  def return?(borrowing)
      if borrowing.state == Borrowing::STATE_BORROWED
        return true
      else
        return false
      end
  end
  def edit?(borrowing)
      if borrowing.state == Borrowing::STATE_BORROWED
        return true
      else
        return false
      end
  end

  def parse_params(params)
    @conditions = ['state = ?', Borrowing::STATE_BORROWED]
    if !params[:book_id].nil?
      @conditions = ['book_id = ?', params[:book_id]]
      params[:book_id] = nil
    end

    if !params[:user_id].nil?
      @conditions = ['user_id = ?', params[:user_id]]
      params[:user_id] = nil
    end

    if !params[:state].nil?
      @conditions = ["state = ?", params[:state]]
      params[:state] = nil
    end

  end
end
